package com.czy.tank.config;

import com.czy.tank.utils.ImageUtil;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

/********************************************************************
 * @brief 图片资源管理
 * @version 0.1
 * @date 2022年08月31日 15:47
 * @author changziyang
 ********************************************************************/
public class ResourceMgr {
    /*我方坦克图片*/
    public static BufferedImage goodTank1L, goodTank1U, goodTank1R, goodTank1D;
    public static BufferedImage goodTank2L, goodTank2U, goodTank2R, goodTank2D;
    /*敌方坦克图片 方向 左上右下*/
    public static BufferedImage badTank1L, badTank1U, badTank1R, badTank1D;
    public static BufferedImage badTank2L, badTank2U, badTank2R, badTank2D;
    /*子弹图片 方向 左上右下*/
    public static BufferedImage bulletL,bulletU,bulletR,bulletD;
    /*我方坦克爆炸图片*/
    public static BufferedImage[] goodExplodes = new BufferedImage[10];
    /*敌方坦克爆炸图片*/
    public static BufferedImage[] badExplodes = new BufferedImage[16];

    static {
        try {
            /*tankL = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/tankL.gif"));
            tankU = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/tankU.gif"));
            tankR = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/tankR.gif"));
            tankD = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/tankD.gif"));

            bulletL = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletL.gif"));
            bulletU = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletU.gif"));
            bulletR = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletR.gif"));
            bulletD = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletD.gif"));*/

            /*只需一个上方向的图片，通过旋转得到其他三个方向*/
            goodTank1U = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/GoodTank1.png"));
            goodTank1L = ImageUtil.rotateImage(goodTank1U, -90);
            goodTank1R = ImageUtil.rotateImage(goodTank1U, 90);
            goodTank1D = ImageUtil.rotateImage(goodTank1U, 180);

            goodTank2U = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/GoodTank2.png"));
            goodTank2L = ImageUtil.rotateImage(goodTank2U, -90);
            goodTank2R = ImageUtil.rotateImage(goodTank2U, 90);
            goodTank2D = ImageUtil.rotateImage(goodTank2U, 180);

            badTank1U = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/BadTank1.png"));
            badTank1L = ImageUtil.rotateImage(badTank1U, -90);
            badTank1R = ImageUtil.rotateImage(badTank1U, 90);
            badTank1D = ImageUtil.rotateImage(badTank1U, 180);

            badTank2U = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/BadTank2.png"));
            badTank2L = ImageUtil.rotateImage(badTank2U, -90);
            badTank2R = ImageUtil.rotateImage(badTank2U, 90);
            badTank2D = ImageUtil.rotateImage(badTank2U, 180);

            bulletU = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletU.png"));
            bulletL = ImageUtil.rotateImage(bulletU, -90);
            bulletR = ImageUtil.rotateImage(bulletU, 90);
            bulletD = ImageUtil.rotateImage(bulletU, 180);

            /*初始化主战坦克爆炸图片*/
            for(int i=0; i<10; i++){
                goodExplodes[i] = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/" + (i+1) + ".gif"));
            }
            /*初始化地方坦克爆炸图片*/
            for(int i=0; i<16; i++){
                badExplodes[i] = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/e" + (i+1) + ".gif"));
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
